from stock.stock_base_daily import reload_daily_k
from stock import stock_base_daily
from datetime import datetime
from kimi_stock import sendAllStock,kimiStock,send_email
from stock.kline_handler import analyze
from logger import logger

# 在 main.py 中使用 logger
logger.info('This is an info message from main.py')


# 选择需要的字段
selected_fields = ['date','code', 'open', 'high', 'low', 'close', 'preclose', 'volume']
# 读取配置信息
reload_daily_k()
_stocks = stock_base_daily.check_daily_all()
sub = "stock info base - " + datetime.now().strftime('%Y-%m-%d')
if _stocks:
    sendAllStock(sub, _stocks)
    kimi_stock = []
    analyze = analyze()
    for __code, __date in _stocks:
        df = stock_base_daily.get_daily_file(__code, selected_fields=selected_fields)
        if analyze.excute(__code, df):
            logger.logger.info("股票代码：" + __code + " 加入kimi！")
            kimi_stock.append([__code, __date])
    kimiStock(kimi_stock)
else:
    send_email(sub, "今天没有可关注的股票")
logger.info("总体结束")